package managerprojectsplugin.handlers;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

import br.com.managerprojectplugin.abstracts.MppAbstractHandler;
import br.com.managerprojectplugin.editor.EditUseCaseEditor;
import br.com.managerprojectplugin.model.Usecase;

public class OpenEditUseCaseEditorHandler extends MppAbstractHandler {
	
	

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		try {
			setUseCase((Usecase) event.getTrigger());
			IEditorInput input = new IEditorInput() {

				@SuppressWarnings("rawtypes")
				@Override
				public Object getAdapter(Class adapter) {
					return Platform.getAdapterManager().getAdapter(
							new Object(), adapter);
				}

				@Override
				public String getToolTipText() {
					return "UseCase Editor"; //$NON-NLS-1$
				}

				@Override
				public IPersistableElement getPersistable() {
					return null;
				}

				@Override
				public String getName() {
					return ""; //$NON-NLS-1$
				}
				
				

				@Override
				public ImageDescriptor getImageDescriptor() {
					return null;
				}

				@Override
				public boolean exists() {
					return false;
				}
			};

			IWorkbenchPage page = PlatformUI.getWorkbench()
					.getActiveWorkbenchWindow().getActivePage();
			page.openEditor(new EditUseCaseEditor(getUseCase()), EditUseCaseEditor.ID);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
		return null;
	}

}
